import pyttsx3

def get_content(filename):
    content = ""
    with open(filename, "r", encoding="utf-8") as f:
        content = f.read()
    print(content)
    return content

def gen_voice(filename):
    engine = pyttsx3.init()
    
    rate = engine.getProperty('rate')
    engine.setProperty('rate', rate - 30)
    
    content = get_content(filename)
    engine.say(content)
    engine.save_to_file(content, filename.replace(".txt", ".mp3"))
    
    engine.runAndWait()
    engine.stop()
    
if __name__ == '__main__':
    filename = 'abc.txt'
    gen_voice(filename)